﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.MenuCommand;
using B.S.DataBase.MyRead.API.Appicant.Command.RoleMenuCommand;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.RoleMenuCommandHandler
{
    /// <summary>
    /// 查询菜单名称
    /// </summary>
    public class GetRoleMenuNameCommandHandler : IRequestHandler<GetRoleMenuNameCommand, APIResult<List<MenuModel>>>
    {
        private readonly IBaseRepository<MenuModel> menuRepos;

        public GetRoleMenuNameCommandHandler(IBaseRepository<MenuModel> menuRepos)
        {
            this.menuRepos = menuRepos;
        }


        /// <summary>
        /// 查询菜单名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<MenuModel>>> Handle(GetRoleMenuNameCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<MenuModel>> result = new APIResult<List<MenuModel>> ();
            var list = menuRepos.GetAll().Result;
            result.data = list.ToList();
            return await Task.FromResult (result);
        }
    }
}
